/*
 * *******************************************************************
 *   @项目名称: BHex Android
 *   @文件名称: FinanceApi.java
 *   @Date: 19-3-8 下午3:49
 *   @Author: ppzhao
 *   @Description:
 *   @Copyright（C）: 2019 BlueHelix Inc.   All rights reserved.
 *   注意：本内容仅限于内部传阅，禁止外泄以及用于其他的商业目的.
 *  *******************************************************************
 */

package io.bhex.sdk.finance;

import android.text.TextUtils;

import io.bhex.baselib.constant.AppData;
import io.bhex.baselib.constant.Fields;
import io.bhex.baselib.network.BParamsBuilder;
import io.bhex.baselib.network.HttpUtils;
import io.bhex.baselib.network.listener.SimpleResponseListener;
import io.bhex.baselib.network.params.PostParams;
import io.bhex.baselib.network.response.ResponseListener;
import io.bhex.sdk.OTCUrls;
import io.bhex.sdk.account.UserInfo;
import io.bhex.sdk.finance.bean.AssetDetailResponse;
import io.bhex.sdk.finance.bean.FinanceAssetDetailResponse;
import io.bhex.sdk.finance.bean.FinanceBean;
import io.bhex.sdk.finance.bean.FinanceListResponse;
import io.bhex.sdk.finance.bean.FinanceOrderListResponse;
import io.bhex.sdk.finance.bean.FinanceRecordBeanResponse;
import io.bhex.sdk.finance.bean.RecordBeanResponse;
import io.bhex.sdk.trade.bean.CoinplusAssetResponse;

public class FinanceApi {
    /**
     * 获取理财列表
     * @param listener
     */
    public static void getFinanceAssetList(ResponseListener<CoinplusAssetResponse> listener){
        if(!UserInfo.isLogin())
            return;
        PostParams params = BParamsBuilder.post()
                .url(OTCUrls.FINANCE_ASSET_LIST)
                .build();
        HttpUtils.getInstance().request(params,CoinplusAssetResponse.class,listener);
    }

    /**
     * 获取理财列表
     * @param listener
     */
    public static void getFinanceOrderList(String pageId, SimpleResponseListener<FinanceOrderListResponse> listener){
        if(!UserInfo.isLogin())
            return;
        PostParams.Builder builder = new BParamsBuilder().post();
        builder.url(OTCUrls.FINANCE_ORDER_LIST)
                .addParam(Fields.FIELD_LIMIT, AppData.Config.PAGE_LIMIT);
        if(!TextUtils.isEmpty(pageId))
            builder.addParam(Fields.FIELD_ORDER_ID_PAGE_FROM, pageId);
        PostParams params = builder.build();
        HttpUtils.getInstance().request(params,FinanceOrderListResponse.class,listener);
    }

    /**
     * 获取理财列表
     * @param listener
     */
    public static void getFinanceList(SimpleResponseListener<FinanceListResponse> listener){
        PostParams params = BParamsBuilder.post()
                .url(OTCUrls.FINANCE_LIST)
                .build();
        HttpUtils.getInstance().request(params,FinanceListResponse.class,listener);
    }

    /**
     * 获取理财详情
     * @param listener
     */
    public static void getFinanceDetail(String financeId,SimpleResponseListener<FinanceBean> listener){
        PostParams params = BParamsBuilder.post()
                .url(OTCUrls.FINANCE_DETAIL)
                .addParam("id",financeId)
                .build();
        HttpUtils.getInstance().request(params,FinanceBean.class,listener);
    }

    /**
     * 获取资产详情
     * @param listener
     */
    public static void getFinanceAssetDetail(String financeId,SimpleResponseListener<AssetDetailResponse> listener){
        PostParams params = BParamsBuilder.post()
                .url(OTCUrls.FINANCE_ASSET_DETAIL)
                .addParam("productId",financeId)
                .build();
        HttpUtils.getInstance().request(params,AssetDetailResponse.class,listener);
    }

    /**
     * 申购
     * @param listener
     */
    public static void financePurchase(String productId,String amount,SimpleResponseListener<FinanceRecordBeanResponse> listener){
        PostParams params = BParamsBuilder.post()
                .url(OTCUrls.FINANCE_PURCHASE)
                .addParam("productId",productId)
                .addParam("amount",amount)
                .build();
        HttpUtils.getInstance().request(params,FinanceRecordBeanResponse.class,listener);
    }

    /**
     * 赎回
     * @param listener
     */
    public static void financeRedeem(String productId,String amount,SimpleResponseListener<FinanceRecordBeanResponse> listener){
        PostParams params = BParamsBuilder.post()
                .url(OTCUrls.FINANCE_REDEEM)
                .addParam("productId",productId)
                .addParam("amount",amount)
                .build();
        HttpUtils.getInstance().request(params,FinanceRecordBeanResponse.class,listener);
    }

    /**
     * 资产记录详情
     * @param listener
     */
    public static void financeRecordDetail(String recordId,SimpleResponseListener<RecordBeanResponse> listener){
        PostParams params = BParamsBuilder.post()
                .url(OTCUrls.FINANCE_RECORD_GET)
                .addParam("recordId",recordId)
                .build();
        HttpUtils.getInstance().request(params,RecordBeanResponse.class,listener);
    }

    /**
     * 资产记录详情
     * @param listener
     */
    public static void financeAssetDetail(String productId,SimpleResponseListener<FinanceAssetDetailResponse> listener){
        PostParams params = BParamsBuilder.post()
                .url(OTCUrls.FINANCE_ASSET_DETAIL)
                .addParam("productId",productId)
                .build();
        HttpUtils.getInstance().request(params,FinanceAssetDetailResponse.class,listener);
    }
}
